package com.yongbao.service.impl;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yongbao.common.PageInfo;
import com.yongbao.common.utils.AssertUtil;
import com.yongbao.model.dtomapper.DishTimeSettingDtoMapper;
import com.yongbao.model.domain.DishTimeSettingDO;
import com.yongbao.mapper.DishTimeSettingMapper;
import com.yongbao.model.request.DishTimeSettingRequest;
import com.yongbao.model.util.DishTimeSettingConvert;
import com.yongbao.service.DishTimeSettingService;
import com.yongbao.model.vo.DishTimeSettingVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zhanghong
 */
@Service
public class DishTimeSettingServiceImpl extends ServiceImpl<DishTimeSettingMapper, DishTimeSettingDO> implements DishTimeSettingService {
    @Autowired
    private DishTimeSettingMapper dishTimeSettingMapper;

    @Override
    public DishTimeSettingVO getByKey(long id) {
        DishTimeSettingVO dishTimeSettingVO = DishTimeSettingDtoMapper.INSTANCE.do2VO(getById(id));
        return dishTimeSettingVO;
    }

    @Override
    public PageInfo<DishTimeSettingVO> pageQuery(DishTimeSettingRequest request) {
        long count = dishTimeSettingMapper.pageCount(request);
        List<DishTimeSettingDO> list = dishTimeSettingMapper.pageQuery(request, request.getPageSize(), request.fetchOffSet());
        List<DishTimeSettingVO> dishTimeSettingVOList = DishTimeSettingConvert.buildDishTimeSettingVoList(list);
        return new PageInfo(request.getPageNum(), request.getPageSize(), dishTimeSettingVOList, count);
    }

    @Override
    public List<DishTimeSettingVO> listQuery(DishTimeSettingRequest request) {
        List<DishTimeSettingDO> list = dishTimeSettingMapper.selectDOList(DishTimeSettingDtoMapper.INSTANCE.request2DO(request));
        List<DishTimeSettingVO> dishTimeSettingVOS = DishTimeSettingConvert.buildDishTimeSettingVoList(list);
        return dishTimeSettingVOS;
    }

    @Override
    public Boolean add(DishTimeSettingRequest request) {
        save(DishTimeSettingDtoMapper.INSTANCE.request2DO(request));
        return true;
    }

    @Override
    public Boolean updateByKey(DishTimeSettingRequest request) {
        AssertUtil.assertNotNull(request.getId(), "id不能为空");
        saveOrUpdate(DishTimeSettingDtoMapper.INSTANCE.request2DO(request));
        return true;
    }

    @Override
    public Boolean delByIds(String ids) {
        dishTimeSettingMapper.deleteDOByIds(Convert.toStrArray(ids));
        return true;
    }
}
